﻿using StarPizza.Model.Core;
using StarPizza.ViewModel.Core;
using System.ComponentModel;

namespace StarPizza.ViewModel.ChefSystem
{
    class ChefPizzaCreator : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        PizzaComposer pizzaComposer;
        Catalogue catalogue;

        public PizzaComposer PizzaComposer { get { return pizzaComposer; } }

        private string name;
        public string Name
        {
            get { return name; }
            set
            {
                if (value != name)
                {
                    name = value;
                    OnPropertyChanged("Name");
                }
            }
        }

        public ChefPizzaCreator(PizzaComposer pizzaComposer, Catalogue catalogue)
        {
            this.pizzaComposer = pizzaComposer;
            this.catalogue = catalogue;
            Name = "New pizza by the Chef";
        }

        public void FinishedPizzaDesign()
        {
            var template = pizzaComposer.ProvidePizzaTemplate(Name);
            pizzaComposer.ClearChosenToppingVMs();
            catalogue.AddPizzaTemplate(template);
        }
    }
}
